/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.mobiubiq.directory.client.data;

import java.util.Vector;
import javax.microedition.lcdui.Image;
import org.kalmeo.kuix.core.Kuix;
import org.kalmeo.kuix.core.KuixConstants;
import org.kalmeo.kuix.core.model.DataProvider;
import org.mobiubiq.directory.client.object.AbstractObject;

/**
 *
     * @author Marnix Renne
 */
public class Service extends DataProvider {

    public static final String ID = "id";
    public static final String NAME = "name";
    public static final String COMPANY = "company";
    public static final String VERSION = "version";
    public static final String DESCRIPTION = "description";
    public static final String URL = "url";
    public static final String ICON = "icon";
    public static final String SETTINGS = "settings";

    private String id;
    private String name;
    private String company;
    private String description;
    private String version;
    private String url;
    private byte[] iconBinary;
    private Image icon;
    private Vector settings;
    private AbstractObject object;

    public Service(AbstractObject object) {
        super();
        this.object = object;
    }

    public void setIconBinary(byte[] data) {
        iconBinary = data;
    }

    protected Object getUserDefinedValue(String property) {
        if (ID.equals(property)) {
            return id;
        }
        if (NAME.equals(property)) {
            return name;
        }
        if (VERSION.equals(property)) {
            return version;
        }
        if (DESCRIPTION.equals(property)) {
            return description;
        }
        if (URL.equals(property)) {
            return url;
        }
        if (SETTINGS.equals(property)) {
            return settings;
        }
        if (ICON.equals(property)) {
            if (iconBinary != null) {
                try {
                    icon = Image.createImage(iconBinary, 0, iconBinary.length);
                    return icon;
                } catch (Throwable t) {
                    Kuix.alert(t.getMessage(), KuixConstants.ALERT_ERROR);
                }
            }
        }
        return null;
    }

    public void setId(String id) {
        this.id = id;
        dispatchUpdateEvent(ID);
    }

    public void setCompany(String company) {
        this.company = company;
        dispatchUpdateEvent(COMPANY);
    }

    public void setName(String name) {
        this.name = name;
        dispatchUpdateEvent(NAME);
    }

    public void setVersion(String version) {
        this.version = version;
        dispatchUpdateEvent(VERSION);
    }

    public void setDescription(String description) {
        this.description = description;
        dispatchUpdateEvent(DESCRIPTION);
    }

    public void setSettings(Vector settings) {
        this.settings = settings;
        dispatchUpdateEvent(SETTINGS);
    }
    
    public void setUrl(String url) {
        this.url = url;
        dispatchUpdateEvent(URL);
    }

    public String getUrl() {
        return url;
    }

    public AbstractObject getObject() {
        return object;
    }
    
    public String getId() {
        return id;
    }
    
    public String getName() {
        return name;
    }
    
    public Vector getSettings() {
        return settings;
    }
    
    public Image getIcon() {
        return icon;
    }
}
